const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/users',{useUnifiedTopology: true,useNewUrlParser: true})
  .then(()=> console.log('链接成功'))
  .catch(err => console.log(err,'链接失败'))


  var schema = new mongoose.Schema({
    name:    String,
    binary:  Buffer,
    living:  Boolean,
    updated: { type: Date, default: Date.now },
    age:     { type: Number, min: 18, max: 65 },
    array:      [],
    ofString:   [String],
    ofNumber:   [Number],
    ofDates:    [Date],
    ofBuffer:   [Buffer],
    ofBoolean:  [Boolean],
    ofArrays:   [[]],
    ofArrayOfNumbers: [[Number]],
    nested: {
      stuff: { type: String, lowercase: true, trim: true }
    }
  })
  
  // example use
  
  var Thing = mongoose.model('Thing', schema);
  
  var m = new Thing;
  m.name = 'Statue of Liberty';
  m.age = 125;
  m.updated = new Date;
  m.binary = new Buffer(0);
  m.living = false;
  m.mixed = { any: { thing: 'i want' } };
  m.markModified('mixed');
  m._someId = new mongoose.Types.ObjectId;
  m.array.push(1);
  m.ofString.push("strings!");
  m.ofNumber.unshift(1,2,3,4);
  m.ofDates.addToSet(new Date);
  m.ofBuffer.pop();
  m.ofMixed = [1, [], 'three', { four: 5 }];
  m.nested.stuff = 'good';
  m.save();
// const UserSchema = new mongoose.Schema({
//   sites: [Object],
//   User: [Object],
//   name: String,
//   age: Number
// });

// const User = mongoose.model('User',UserSchema);

// // const users = new User({
// //   sites:[{"a":1}],
// //   User:[{"a":1}]
// // })
// // users.save();

// User.updateOne({name:"luo"},{name:"gg"}).then(res=> console.log(res))
